﻿package com.dg.gaming.api.common.playerstate
{
	import com.dg.gaming.api.common.Game;
	import com.dg.gaming.api.common.PlayerList;
	import com.dg.gaming.api.common.Table;
	import com.dg.gaming.api.common.util.DGLabels;

	/**
	 * ...
	 * @author
	 */
	public class PlayerStateSeated extends PlayerState
	{

		/**
		 * If a player stands his state goes back to viewing.
		 *
		 * @see com.dg.gaming.api.common.playerstate.PlayerState#stand()
		 */
		public override function stand():PlayerState
		{
			return new PlayerStateViewing();
		}

		/**
		 * Player state goes to ready to start.
		 *
		 * @see com.dg.gaming.api.common.playerstate.PlayerState#start()
		 */
		public override function start():PlayerState
		{
			return new PlayerStateReady();
		}

		/**
		 * Once seated a player can stand back up again.
		 *
		 * @see com.dg.gaming.api.common.playerstate.PlayerState#canStand(com.dg.gaming.api.common.PlayerList)
		 */
		public override function canStand(table:Table):Boolean
		{
			return true;
		}

		/**
		 * A player can start if the minimum number of players are seated or are
		 * ready to start.
		 *
		 * @see com.dg.gaming.api.common.playerstate.PlayerState#canStart(com.dg.gaming.api.common.PlayerList)
		 */
		public override function canStart(table:Table, game:Game):Boolean
		{
			var minPlayers:int=game.getMinNumOfPlayers();

			var players:PlayerList=table.getPlayerList();
			var curPlayersSeatedAndReady:int=players.getPlayerStateCount(SEATED) + players.getPlayerStateCount(READY_TO_START);
			return (curPlayersSeatedAndReady >= minPlayers);
		}

		// Defaults
		public override function sit():PlayerState
		{
			return this;
		}

		public override function canSit(table:Table):Boolean
		{
			return false;
		}

		public override function canOfferDrawResign():Boolean
		{
			return false;
		}

		/**
		 * @see com.dg.gaming.api.common.playerstate.PlayerState#intValue()
		 */
		public override function stringValue():String
		{
			return SEATED;
		}

		public override function toString():String
		{
			return DGLabels.getInstance().getValue("seated");
		}


	}

}